<template>
  <div>
    <el-dialog class="positionDialog" :title="this.ruleForm.id ? '修改' : '新增'" :visible="showDialog" width="98%"
      :before-close="handleClose" :modal="false" :close-on-click-modal="false">
      <div class="content">
        <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="120px" class="demo-ruleForm">
          <div class="title fir-title">
            <svg-icon class="svg-icon" icon-class="infoAdd" />
            <span>入场登记</span>
          </div>
          <div class="form">
            <el-form-item label="车牌号" prop="carNumber">
              <el-select style="width: 100%;" v-model="ruleForm.carNumber" filterable placeholder="请选择车牌号或输入关键词">
                <el-option v-for="item in carList" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
              <el-button class="redAdd" @click="handleShowAddDialog('carInfo')">新增</el-button>
            </el-form-item>
          </div>
          <div class="title">
            车辆信息
          </div>
          <div class="form">
            <el-form-item label="智慧卡号" prop="">
              <el-input v-model="ruleForm.cardNumber" placeholder="请输入智慧卡号" :disabled="true"></el-input>
            </el-form-item>
            <!-- <el-form-item label="车牌号" prop="carNumber">
              <el-select style="width: 100%;" v-model="ruleForm.carNumber" filterable placeholder="请选择车牌号或输入关键词">
                <el-option v-for="item in carList" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
              <el-button class="redAdd" @click="handleShowAddDialog('carInfo')">新增</el-button>
            </el-form-item> -->
            <el-form-item label="司机姓名" prop="driverPhone">
              <el-select style="width: 100%;" v-model="ruleForm.driverPhone" filterable placeholder="请选择司机姓名或输入关键词"
                @change="handleDriverName">
                <el-option v-for="item, index in driverList" :key="item.value + index" :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
              <el-button class="redAdd" @click="handleShowAddDialog('driverInfo')">新增</el-button>
            </el-form-item>
            <el-form-item label="押车人姓名" prop="">
              <el-select style="width: 100%;" v-model="ruleForm.personPhone" filterable placeholder="请选择押车人姓名或输入关键词"
                @change="handleEscortPerson">
                <el-option v-for="item in escortPersonList" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
              <el-button class="redAdd" @click="handleShowAddDialog('betcarInfo')">新增</el-button>
            </el-form-item>
          </div>
          <div class="title">
            <span>基本信息</span>
          </div>
          <div class="form">
            <el-form-item label="农场" prop="farmCode">
              <el-select style="width: 100%;" v-model="ruleForm.farmCode" filterable placeholder="请选择农场或输入关键词"
                @change="handleSelectTeam">
                <el-option v-for="item in farmList" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="生产队" prop="sourceTeam">
              <el-select style="width: 100%;" v-model="ruleForm.sourceTeam" filterable placeholder="请选择生产队或输入关键词"
                @change="handleChangeMassifNumber">
                <el-option v-for="item in teamList" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="地块号" prop="massifNumber">
              <el-select style="width: 100%;" v-model="ruleForm.massifNumber" filterable placeholder="请选择地块号或输入关键词"
                :disabled="ruleForm.sourceTeam ? false : true" @change="setmassifName">
                <el-option v-for="item, index in massifNumberList" :key="item.value + index" :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="种类" prop="cropType">
              <el-select style="width: 100%;" v-model="ruleForm.cropType" filterable placeholder="请选择种类或输入关键词"
                @change="handleChangeCropType">
                <el-option v-for="item in cropinfoList" :key="item.value" :label="item.label" :value="item.label">
                </el-option>
              </el-select>
              <el-button class="redAdd" @click="handleShowAddDialog('cropInfo')">新增</el-button>
            </el-form-item>
            <el-form-item label="作物品种" prop="cropVarieties">
              <el-select style="width: 100%;" v-model="ruleForm.cropVarieties" filterable placeholder="请选择作物品种或输入关键词"
                :disabled="ruleForm.cropType ? false : true">
                <el-option v-for="item, index in cropVarietiesList" :key="item.value + index" :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
              <el-button class="redAdd" @click="handleShowAddDialog('cropVariety')">新增</el-button>
            </el-form-item>
            <el-form-item label="类别" prop="cropCategory">
              <el-select style="width: 100%;" v-model="ruleForm.cropCategory" filterable placeholder="请选择类别或输入关键词">
                <el-option v-for="item in categoryList" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
              <el-button class="redAdd" @click="handleShowAddDialog('cropType')">新增</el-button>
            </el-form-item>
            <el-form-item label="开票人" prop="biller">
              <el-input v-model="ruleForm.biller" placeholder="请输入开票人"></el-input>
            </el-form-item>
          </div>
          <div class="title">
            <span>过磅信息</span>
          </div>
          <div class="form">
            <el-form-item label="毛重(kg)" prop="gw">
              <el-input oninput="value=value.replace(/[^0-9.]/g,'')" v-model="ruleForm.gw"
                :placeholder="ruleForm.cropType ? '请输入毛重' : '请选择作物'" @blur="handleGW"
                :disabled="ruleForm.cropType ? false : true"></el-input>
            </el-form-item>
            <el-form-item label="皮重(kg)" prop="tare">
              <el-input oninput="value=value.replace(/[^0-9.]/g,'')" v-model="ruleForm.tare"
                :placeholder="ruleForm.cropType ? '请输入皮重' : '请选择作物'" @blur="handleTARE"
                :disabled="ruleForm.cropType ? false : true"></el-input>
            </el-form-item>
            <el-form-item label="净重(kg)" prop="">
              <el-input v-model="ruleForm.nw" :placeholder="ruleForm.cropType ? '请输入皮重' : '过毛重-过皮重'"
                :disabled="true"></el-input>
            </el-form-item>
            <el-form-item label="过毛时间" prop="hairingTime">
              <el-date-picker style="width: 100%;" v-model="ruleForm.hairingTime" format="yyyy-MM-dd HH:mm:ss"
                value-format="yyyy-MM-dd HH:mm:ss" type="datetime" placeholder="请选择过毛时间">
              </el-date-picker>
            </el-form-item>
            <el-form-item label="过皮时间" prop="peelingTime">
              <el-date-picker style="width: 100%;" v-model="ruleForm.peelingTime" format="yyyy-MM-dd HH:mm:ss"
                value-format="yyyy-MM-dd HH:mm:ss" type="datetime" placeholder="请选择过皮时间">
              </el-date-picker>
            </el-form-item>
            <el-form-item label="过磅人" prop="weighPeople">
              <el-input v-model="ruleForm.weighPeople" placeholder="请输入过磅人"></el-input>
            </el-form-item>
          </div>
          <div class="title">
            <span>扦样质检信息</span>
          </div>
          <div class="form">
            <el-form-item label="含水量(%)" prop="moistureContent">
              <el-input class="parentInput" oninput="value=value.replace(/[^0-9.]/g,'')"
                v-model="ruleForm.moistureContent" :placeholder="ruleForm.cropType ? '请输入含水量' : '请选择作物'"
                @blur="formatWater"></el-input>
              <span v-if="showWater" class="tips">{{ water ? `当前作物标准含水量为 ${water} %` : '当前作物暂无标准含水量' }}</span>
            </el-form-item>
          </div>
          <div class="title">
            <span>实际重量信息</span>
          </div>
          <div class="form">
            <el-form-item label="水份扣重(kg)" prop="waterBuckle">
              <el-input class="parentInput" v-model="ruleForm.waterBuckle" placeholder="当前作物存在含水量标准时计算"
                :disabled="true"></el-input>
              <span class="tips">水份扣重=(实时水份含量-标净准含水量)*净重</span>
              <el-button class="redAdd" @click="handleShowAddDialog('waterStandard')">新增</el-button>
            </el-form-item>
            <el-form-item class="parentInput" label="扣杂重(kg)" prop="deductBuckle">
              <el-input v-model="ruleForm.deductBuckle" placeholder="当前作物存在含水量标准时计算" :disabled="true"></el-input>
              <span class="tips">扣杂重=净重*标准扣杂百分值</span>
              <el-button class="redAdd" @click="handleShowAddDialog('impurityStandard')">新增</el-button>
            </el-form-item>
            <el-form-item class="parentInput" label="实重(kg)" prop="solid">
              <el-input v-model="ruleForm.solid" placeholder="得出水份扣重和扣杂重后计算" :disabled="true"></el-input>
              <span class="tips">实重=净重-水份扣重-扣杂重</span>
            </el-form-item>
          </div>
          <div class="form" style="height: 40px;"></div>
        </el-form>
      </div>

      <div class="dialog-footer">
        <el-button class="submit" @click="handleSubmit">确 认</el-button>
        <el-button class="back" @click="handleClose">返 回</el-button>
      </div>
    </el-dialog>

    <!-- 新增车牌号 -->
    <CarInfo ref="CarInfo" :showDialog.sync="carInfo" @handleRefresh="handleRefreshList('carInfo')"></CarInfo>
    <!-- 司机信息 -->
    <DriverInfo ref="DriverInfo" :showDialog.sync="driverInfo" @handleRefresh="handleRefreshList('driverInfo')">
    </DriverInfo>
    <!-- 押车人信息 -->
    <BetcarInfo ref="BetcarInfo" :showDialog.sync="betcarInfo" @handleRefresh="handleRefreshList('betcarInfo')">
    </BetcarInfo>
    <!-- 种类 -->
    <CropInfo ref="CropInfo" :showDialog.sync="cropInfo" @handleRefresh="handleRefreshList('cropInfo')"></CropInfo>
    <!-- 作物品种 -->
    <CropVariety ref="CropVariety" :showDialog.sync="cropVariety" @handleRefresh="handleRefreshList('cropVariety')">
    </CropVariety>
    <!-- 作物类别 -->
    <CropType ref="CropType" :showDialog.sync="cropType" @handleRefresh="handleRefreshList('cropType')"></CropType>
    <!-- 水份扣重 -->
    <WaterStandard ref="WaterStandard" :showDialog.sync="waterStandard"
      @handleRefresh="handleRefreshList('waterStandard')">
    </WaterStandard>
    <!-- 扣杂标准 -->
    <ImpurityStandard ref="ImpurityStandard" :showDialog.sync="impurityStandard"
      @handleRefresh="handleRefreshList('impurityStandard')"></ImpurityStandard>
  </div>
</template>

<script>
import '../scss/style.scss'
import rules from '@/utils/rules'
import { Message } from 'element-ui'
import { getInfo } from '@/utils/auth'
import { filterSelect, formatDate } from '@/utils/methods'
import { selectApi, carinfoApi, driverInfoApi, escortPersonApi, getSeasonListApi, cropinfoSelectApi, categorySelectApi } from '@/api/select'
import { getPlotUnitListApi, cropTypeApi, addApi, editApi, waterContentApi, deductStandardApi, getInfoApi } from '@/api/inStorage'
import CarInfo from '@/views/info/components/CarInfo/dialog/AddPopu.vue'
import DriverInfo from '@/views/info/components/DriverInfo/dialog/AddPopu.vue'
import BetcarInfo from '@/views/info/components/BetcarInfo/dialog/AddPopu.vue'
import CropInfo from '@/views/info/components/CropInfo/dialog/AddPopu.vue'
import CropVariety from '@/views/info/components/CropVariety/dialog/AddPopu.vue'
import CropType from '@/views/info/components/CropType/dialog/AddPopu.vue'
import WaterStandard from '@/views/info/components/WaterStandard/dialog/AddPopu.vue'
import ImpurityStandard from '@/views/info/components/ImpurityStandard/dialog/AddPopu.vue'
export default {
  props: ['showDialog'],
  components: {
    CarInfo,
    DriverInfo,
    BetcarInfo,
    CropInfo,
    CropVariety,
    CropType,
    WaterStandard,
    ImpurityStandard
  },
  data() {
    return {
      ruleForm: {
        cardNumber: '',
        carNumber: '',
        driverPhone: '',
        driverName: '',
        personPhone: '',
        personName: '',
        farmCode: '',
        teamCode: '',
        // 货物来源生产队
        sourceTeam: '',
        seasonId: '',
        massifNumber: '',
        cropType: '',
        cropVarieties: '',
        cropCategory: '',
        biller: '',
        gw: '',
        tare: '',
        nw: '',
        hairingTime: '',
        peelingTime: '',
        weighPeople: '',
        moistureContent: '',
        waterBuckle: '',
        deductBuckle: '',
        solid: ''
      },
      rules: rules,
      // 车牌号
      carList: [],
      // 司机
      driverList: [],
      // 押车人
      escortPersonList: [],
      // 农场
      farmList: [],
      // 生产队
      teamList: [],
      // 种植季
      seasonList: [],
      seasonYear: new Date().getFullYear() ,
      // 作物种类
      cropinfoList: [],
      // 作物品种
      cropVarietiesList: [],
      // 作物类别
      categoryList: [],
      // 地块号
      massifNumberList: [],
      carInfo: false,
      driverInfo: false,
      betcarInfo: false,
      cropInfo: false,
      cropVariety: false,
      cropType: false,
      waterStandard: false,
      impurityStandard: false,
      // 标准含水量
      water: '',
      showWater: false,
      // 扣杂重
      sundries: '',
    };
  },
  methods: {
    handleClose() {
      this.$emit('update:showDialog', false)
      this.ruleForm = {
        cardNumber: '',
        carNumber: '',
        driverPhone: '',
        driverName: '',
        personPhone: '',
        personName: '',
        farmCode: '',
        teamCode: '',
        // 货物来源生产队
        sourceTeam: '',
        seasonId: '',
        massifNumber: '',
        cropType: '',
        cropVarieties: '',
        cropCategory: '',
        biller: '',
        gw: '',
        tare: '',
        nw: '',
        hairingTime: '',
        peelingTime: '',
        weighPeople: '',
        moistureContent: '',
        waterBuckle: '',
        deductBuckle: '',
        solid: ''
      };
      this.carList = [];
      this.driverList = [];
      this.escortPersonList = [];
      this.farmList = [];
      this.teamList = [];
      this.seasonList = [];
      this.cropinfoList = [];
      this.cropVarietiesList = [];
      this.categoryList = [];
      this.massifNumberList = [];
      this.$refs.ruleForm.resetFields();
      this.water = ''
      this.showWater = false
    },
    handleSubmit() {
      this.$refs.ruleForm.validate(async (valid) => {
        if (valid) {
          if (this.ruleForm.id) {
            let { code } = await editApi({...this.ruleForm,modifyTheID:''})
            if (code == 0) {
              Message({
                message: '修改成功',
                type: 'success',
                duration: 3 * 1000
              })
            }
          } else {
            let { code } = await addApi({...this.ruleForm,modifyTheID:''})
            if (code == 0) {
              Message({
                message: '添加成功',
                type: 'success',
                duration: 3 * 1000
              })
            }
          }
          this.$emit('handleRefresh')
          this.$emit('handleUpdate')
          this.handleClose()
        } else {
          return false;
        }
      });
    },
    // 获取填报人时间
    handleGetInfo() {
      this.ruleForm.weighPeople = JSON.parse(getInfo()).oguName
      this.ruleForm.biller = JSON.parse(getInfo()).oguName
      this.ruleForm.hairingTime = formatDate(new Date())
      this.ruleForm.peelingTime = formatDate(new Date())
    },
    // 回填
    async getInfo(id) {
      let { data } = await getInfoApi({ id })
      this.ruleForm = data
      this.handleGetSelect()
    },
    // 获取下拉框
    handleGetSelect() {
      Promise.all([
        carinfoApi(this.$farmCode),
        driverInfoApi(this.$farmCode),
        escortPersonApi(this.$farmCode),
        selectApi({ type: 'farm_type' }),
        cropinfoSelectApi(),
        cropinfoSelectApi(),
        categorySelectApi(),
        getSeasonListApi(),
      ]).then(resList => {
        this.carList = filterSelect(resList[0].data)
        this.driverList = resList[1].data
        this.escortPersonList = resList[2].data

        if (this.$status != '0') {
          this.farmList = resList[3].data.dictItemList.filter(item => item.value == this.$farmCode)
          this.handleSelectTeam(this.$farmCode)
        } else {

          this.farmList = resList[3].data.dictItemList
        }
        this.seasonList = resList[7].data.data.map(item => {
          return {
            label: item.name,
            value: item.id
          }
        })
        this.ruleForm.seasonId = this.seasonList[0].value
        this.cropinfoList = resList[5].data
        this.categoryList = filterSelect(resList[6].data)
        if (this.ruleForm.id) {
          this.handleCropTypeEdit(this.ruleForm.cropType)
        }
      })
    },
    // 选择生产队
    async handleSelectTeam(e) {
      let i = this.farmList.findIndex(item => item.value == e)
      this.ruleForm.remarks = this.farmList[i].remarks
      let res = await selectApi({ type: e })
      this.ruleForm.farmCode = this.$farmCode
      this.teamList = res.data.dictItemList
      this.ruleForm.teamCode = this.$teamCode
      this.$nextTick(() => {
        this.$refs.ruleForm.clearValidate('teamCode')
        this.$refs.ruleForm.clearValidate('farmCode')
      })
      if (this.ruleForm.sourceTeam && this.ruleForm.id) {
        this.handleChangeMassifNumberEdit()
      }
    },
    setmassifName(e) {
      let i = this.massifNumberList.findIndex(item => item.value == e)
      this.ruleForm.massifName = this.massifNumberList[i].label
    },
    // 选择司机
    handleDriverName(e) {
      let i = this.driverList.findIndex(item => item.value == e)
      this.ruleForm.driverName = this.driverList[i].label
    },
    // 选择司机 escortPersonList
    handleEscortPerson(e) {
      let i = this.escortPersonList.findIndex(item => item.value == e)
      this.ruleForm.personName = this.escortPersonList[i].label
    },
    // 选择地块号
    async handleChangeMassifNumber() {
      this.$set(this.ruleForm, 'massifNumber', '')
      this.massifNumberList = []
      let res = await getPlotUnitListApi({ teamId: this.ruleForm.sourceTeam })
      this.massifNumberList = res.data.map(item => {
        return {
          label: item.massifName,
          value: item.massifNumber
        }
      })
    },
    // 选择地块号
    async handleChangeMassifNumberEdit() {
      let res = await getPlotUnitListApi({ teamId: this.ruleForm.sourceTeam })
      this.massifNumberList = res.data.map(item => {
        return {
          label: item.massifName,
          value: item.massifNumber
        }
      })
    },
    // 选择种类 获取品种
    async handleChangeCropType(e) {
      if (!e) return
      this.handleGetWater()
      this.ruleForm.cropVarieties = ''
      this.ruleForm.gw = ''
      this.ruleForm.tare = ''
      this.ruleForm.nw = ''
      this.ruleForm.moistureContent = ''
      this.ruleForm.waterBuckle = ''
      this.ruleForm.deductBuckle = ''
      this.ruleForm.solid = ''
      let res = await cropTypeApi(e)
      this.cropVarietiesList = filterSelect(res.data)
    },
    // 选择种类 获取品种 修改回填
    async handleCropTypeEdit(e) {
      let res = await cropTypeApi(e)
      this.cropVarietiesList = filterSelect(res.data)
      this.handleWater()
    },
    // 获取 标准含水量 回填
    async handleWater() {
      this.showWater = true
      let { data } = await waterContentApi({ year: this.seasonYear, farmCode: this.ruleForm.farmCode, teamCode: this.ruleForm.teamCode, cropName: this.ruleForm.cropType })
      this.water = data
    },
    // 毛重
    handleGW() {
      if (this.ruleForm.gw) {
        this.ruleForm.gw = (this.ruleForm.gw * 1).toFixed(2)
      }
      if (this.ruleForm.gw && this.ruleForm.gw * 1 <= 0) {
        Message({
          message: '请确认所输入的值大于0',
          type: 'error',
          duration: 3 * 1000
        })
        this.ruleForm.gw = ''
        this.ruleForm.nw = ''
        return
      }
      if (this.ruleForm.tare && (this.ruleForm.gw * 1) > (this.ruleForm.tare * 1)) {
        this.ruleForm.nw = (this.ruleForm.gw - this.ruleForm.tare).toFixed(2)

      } else if (this.ruleForm.tare && (this.ruleForm.gw * 1) <= (this.ruleForm.tare * 1)) {
        Message({
          message: '毛重值应大于皮重值',
          type: 'error',
          duration: 3 * 1000
        })
        this.ruleForm.gw = ''
        this.ruleForm.nw = ''
      }
    },
    // 皮重
    handleTARE() {
      if (this.ruleForm.tare) {
        this.ruleForm.tare = (this.ruleForm.tare * 1).toFixed(2)
      }
      if (this.ruleForm.tare && this.ruleForm.tare * 1 <= 0) {
        Message({
          message: '请确认所输入的值大于0',
          type: 'error',
          duration: 3 * 1000
        })
        this.ruleForm.tare = ''
        this.ruleForm.nw = ''
        return
      }
      if (this.ruleForm.gw && (this.ruleForm.gw * 1) > (this.ruleForm.tare * 1)) {
        this.ruleForm.nw = (this.ruleForm.gw - this.ruleForm.tare).toFixed(2)

      } else if (this.ruleForm.tare && (this.ruleForm.gw * 1) <= (this.ruleForm.tare * 1)) {
        Message({
          message: '毛重值应大于皮重值',
          type: 'error',
          duration: 3 * 1000
        })
        this.ruleForm.tare = ''
        this.ruleForm.nw = ''
      }
    },
    // 标准 含水量    扣杂重
    async handleGetWater() {
      this.showWater = true
      waterContentApi({ year: this.seasonYear, farmCode: this.ruleForm.farmCode, teamCode: this.ruleForm.teamCode, cropName: this.ruleForm.cropType }).then(({ data }) => {
        this.water = data
        if (this.water == null) {
          Message({
            message: '当前作物未填写标准含水量，请填写后再次选择',
            type: 'warning',
            duration: 3 * 1000
          })
        }
      })
      deductStandardApi({ year: this.seasonYear, farmCode: this.ruleForm.farmCode, teamCode: this.ruleForm.teamCode, cropName: this.ruleForm.cropType }).then(({ data }) => {
        this.sundries = data
        if (this.sundries == null) {
          Message({
            message: '当前作物未填写扣杂百分比，请填写后再次选择',
            type: 'warning',
            duration: 3 * 1000
          })
        }
      })
    },
    async formatWater() {
      if (this.ruleForm.moistureContent) {
        this.ruleForm.moistureContent = (this.ruleForm.moistureContent * 1).toFixed(2)
        if (this.water) {
          if ((this.ruleForm.moistureContent * 1) >= (this.water * 1)) {
            this.ruleForm.waterBuckle = (((this.ruleForm.nw * 1) * ((this.ruleForm.moistureContent * 1) - (this.water * 1))) / 100).toFixed(2)
            this.ruleForm.solid = ((this.ruleForm.nw * 1) - ((this.ruleForm.waterBuckle * 1) + (this.ruleForm.deductBuckle * 1))).toFixed(2)
          } else {
            Message({
              message: '当前含水量小于标准含水量，将不予计算',
              type: 'warning',
              duration: 3 * 1000
            })
            this.ruleForm.waterBuckle = ''
            this.ruleForm.solid = ''
          }
        }
      } else {
        this.ruleForm.waterBuckle = ''
        // this.ruleForm.deductBuckle = ''
        this.ruleForm.solid = ''
      }
    },
    // 新增弹框
    async handleShowAddDialog(val) {
      if (val === 'carInfo') {
        this.$refs.CarInfo.handleGetInfo()
        this.$refs.CarInfo.handleGetSelect()
        this.carInfo = true
      }
      if (val === 'driverInfo') {
        this.$refs.DriverInfo.handleGetInfo()
        this.$refs.DriverInfo.handleGetSelect()
        this.driverInfo = true
      }
      if (val === 'betcarInfo') {
        this.$refs.BetcarInfo.handleGetInfo()
        this.betcarInfo = true
      }
      if (val === 'cropInfo') {
        this.$refs.CropInfo.handleGetInfo()
        this.cropInfo = true
      }
      if (val === 'cropVariety') {
        this.$refs.CropVariety.handleGetInfo()
        this.$refs.CropVariety.handleGetSelect()
        this.cropVariety = true
      }
      if (val === 'cropType') {
        this.$refs.CropType.handleGetInfo()
        this.cropType = true
      }
      if (val === 'waterStandard') {
        this.$refs.WaterStandard.handleGetInfo()
        this.$refs.WaterStandard.handleGetFarm()
        this.$refs.WaterStandard.handleGetSelect()
        this.waterStandard = true
      }
      if (val === 'impurityStandard') {
        this.$refs.ImpurityStandard.handleGetInfo()
        this.$refs.ImpurityStandard.handleGetFarm()
        this.$refs.ImpurityStandard.handleGetSelect()
        this.impurityStandard = true
      }
    },
    // 更新下拉框
    async handleRefreshList(val) {
      if (val === 'carInfo') {
        let res = await carinfoApi(this.$farmCode)
        this.carList = filterSelect(res.data)
      }
      if (val === 'driverInfo') {
        let res = await driverInfoApi(this.$farmCode)
        this.driverList = res.data
      }
      if (val === 'betcarInfo') {
        let res = await escortPersonApi(this.$farmCode)
        this.escortPersonList = res.data
      }
      if (val === 'cropInfo') {
        let res = await cropinfoSelectApi()
        this.cropinfoList = res.data
      }
      if (val === 'cropVariety') {
        if (!this.ruleForm.cropType) return
        let res = await cropTypeApi(this.ruleForm.cropType)
        this.cropVarietiesList = filterSelect(res.data)
      }
      if (val === 'cropType') {
        let res = await categorySelectApi()
        this.categoryList = filterSelect(res.data)
      }
      if (val === 'waterStandard') {

      }
      if (val === 'impurityStandard') {
      }
    }
  },
  watch: {
    // 监听 obj.value 的变化
    'ruleForm.nw'(newVal, oldVal) {
      if (this.ruleForm.moistureContent && newVal && this.water) {
        // 水份扣重
        this.ruleForm.waterBuckle = (((newVal * 1) * ((this.ruleForm.moistureContent * 1) - (this.water * 1))) / 100).toFixed(2)
        // 实重
        this.ruleForm.solid = ((newVal * 1) - ((this.ruleForm.waterBuckle * 1) + (this.ruleForm.deductBuckle * 1))).toFixed(2)
        if ((this.ruleForm.moistureContent * 1) < (this.water * 1)) {
          Message({
            message: '当前含水量小于标准含水量，将不予计算',
            type: 'warning',
            duration: 3 * 1000
          })
          this.ruleForm.waterBuckle = ''
          this.ruleForm.solid = ''
        }
      }
      // 扣杂重
      if (newVal && this.sundries) {
        this.ruleForm.deductBuckle = ((newVal * 1) * (this.sundries * 1 / 100)).toFixed(2)
      } else {
        this.ruleForm.deductBuckle = ''
      }
      // 有水份扣重 没扣杂重
      if (newVal && this.ruleForm.waterBuckle && !this.ruleForm.deductBuckle) {
        this.ruleForm.solid = ((newVal * 1) - (this.ruleForm.waterBuckle * 1)).toFixed(2)
      }
      // 有扣杂重 没水份扣重
      if (newVal && !this.ruleForm.waterBuckle && this.ruleForm.deductBuckle) {
        this.ruleForm.solid = ((newVal * 1) - (this.ruleForm.deductBuckle * 1)).toFixed(2)
      }
      // 没扣重  实重=净重
      if (newVal && !this.ruleForm.waterBuckle && !this.ruleForm.deductBuckle) {
        this.ruleForm.solid = (newVal * 1).toFixed(2)
      }
    }
  }
}
</script>

<style lang='scss' scoped>
.form {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
}


.el-form-item {
  width: 33%;
  margin-bottom: 20px;
}

.parentInput {
  position: relative;
}

.tips {
  position: absolute;
  color: #666;
  top: 30px;
  font-size: 12px;
}

.fir-title {
  margin-top: 0 !important;
}

.title {
  font-size: 17px !important;
  margin: 5px 0 !important;
}

.content {
  display: flex;
}

.button-box {
  margin-top: 60px;
}

.inStoragePCButton {
  width: 120px;
  height: 10vh;
  position: relative;
  float: left;
  background: #0e7b67;
  color: #fff;
  font-weight: 700;
  font-size: 1.2vw;
  line-height: 10vh;
  text-align: center;
  margin: 2vh 1vw;
  border-radius: 5px;
  cursor: pointer;
}

.dialog-footer {
  width: 180px;
  left: 50%;
  transform: translateX(-50%)
}


::v-deep .el-form-item__content {
  display: flex;
  align-items: center;
  height: 36px;
  line-height: 36px;
}

::v-deep .el-input {
  flex: 1;
  height: 36px;
}

::v-deep .el-select {
  flex: 1;
  height: 36px;
}

::v-deep .el-input__icon {
  line-height: 36px;
}

::v-deep .el-input__inner {
  height: 36px;
}
</style>
